/*
 * Copyright (c) 2025, 廖树财, <study_2030@163.com>
 *
 * PHS2.0-OTA is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2     
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
#pragma once
#include "define.h"
#include "JsonParser.h"
#include <signal.h>
#include "zlog.h"
#include <errno.h>
#include <sys/stat.h>

typedef struct st_IOTA_KILL_PARAM
{
    int pid;
} IOTA_KILL_PARAM;

typedef struct st_IOTA_SERVICE_PARAM
{
    char *service;
} IOTA_SERVICE_PARAM;

typedef struct st_IOTA_NETWORKLIST_PARAM
{
    char dstIp[32];
    char dstPort[16];
    char srcIp[32];
    char srcPort[16];
    char protocol[16];
    int priority;
} IOTA_NETWORKLIST_PARAM, *PIOTA_NETWORKLIST_PARAM;

typedef struct st_IOTA_NIC_PARAM
{
    char *iface;
} IOTA_NIC_PARAM;

typedef struct st_SERVICE_THREAD_PARAMS
{
    char* pcJson;   // 请求json
    bool  action;   // 服务启停，true启动，false停止 
} SERVICE_THREAD_PARAMS;

bool JsonToStruct_ServiceKill(char *pcJson, ST_IOTA_LOG *pcStatusDecs);

bool JsonToStruct_ServiceOnOff(char *pcJson, ST_IOTA_LOG *pcStatusDecs);

bool JsonToStruct_ServiceFirewall(char *pcJson, ST_IOTA_LOG *pcStatusDecs);

int JsonToStruct_ServiceFirewall_V1(char* pcJson, ST_IOTA_LOG* pcStatusDecs);

bool JsonToStruct_ServiceNIC(char *pcJson, ST_IOTA_LOG *pcStatusDecs);

int security_commond(char *pJson);

void commond_init_run();

int terminalServiceUpdate(char *pJson);

int firmwareServiceUpgrade(char* pJson);
int actionPatchUpgrade(char* pJson);
int firmwareServiceDownload(char* pJson);

int actionPatchDownload(char* pJson);

int actionConfigDownalod(char* pJson);

int setFirewallRule(IOTA_NETWORKLIST_PARAM param, char *action);

int setFirewallRule_V1(IOTA_NETWORKLIST_PARAM_V1 param, char* action);

int setFirewallRule_V2(IOTA_NETWORKLIST_PARAM_V2 param, char* action, CommunicationMode mode,int setprio);

int deleteFirewallRule(const char *remoteIP, int remotePort, const char *localIP, int localPort);

int setPort(int port, const char *action);

int setFireWallList(char *pJson, const char *action);

int setNIC(char *pJson, const char *action);

int setNetworkPolicy(char* pJson);

int getNetworkPolicy(char* pJson);


int setPolicySecurity(char *pcJson);
int getPolicySecurity(char *pcJson);

// int setPolicySecuritySsh(char *pcJson);
// int getPolicySecuritySsh(char *pcJson);

int setPolicySecurityVideo(char *pcJson);
int getPolicySecurityVideo(char *pcJson);

// int setPolicySecurityPort(char *pcJson);
// int getPolicySecurityPort(char *pcJson);
